<template>
	<div class="topicManager w944">
		<alert ref="alert"></alert>
		<deleteAlert ref="deleteAlert"></deleteAlert>
		<div class="label_top">
			<p><i class="line"></i>话题管理</p>
			<b class="rightBtn" @click="fenleiButton">话题分类</b>
		</div>
		<div class="label_table">
			<div class="el-tabs-report">
				<a class="listOne">话题列表</a>
				<a class="listTwo advise" @click="topicAudit">话题审核</a>
				<a class="listTwo" @click="importDaoChu">导出数据</a>
				<el-select v-model="sift" class="th_3" @change="getTableList">
					<el-option label="话题筛选" value=""></el-option>
					<el-option label="最新话题" value="1"></el-option>
					<el-option label="最热话题" value="2"></el-option>
					<el-option label="最新跟帖" value="3"></el-option>
					<el-option label="最热跟帖" value="4"></el-option>
					<el-option label="置顶话题" value="5"></el-option>
					<el-option label="置顶跟帖" value="6"></el-option>
				</el-select> 
				<el-select v-model="permission" class="th_2" @change="getTableList">
					<el-option label="话题分类" value=""></el-option>
					<el-option v-for="item in permissionArr" :key="item.id" :label="item.name" :value="item.id"></el-option>
				</el-select>
				<div class="msearch">
					<input placeholder="请输入话题、学员名字……" v-model="search"/>
					<a @click="getPageSearch"><img src="../../assets/qudaoImg/search.png"/></a>
				</div>
			</div>
			<el-table ref="multipleTable" :data="tableData" border @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55"></el-table-column>
				<el-table-column prop="title" label="话题"></el-table-column>
				<el-table-column label="创建者">
					<template slot-scope="scope">
						<span><img src="../../assets/qudaoImg/anonymous.png" v-if="scope.row.cryptonym==1">{{scope.row.nickname}}<i class="cancellation" v-if="scope.row.status==0">（已注销）</i></span>
					</template>
				</el-table-column>
				<el-table-column label="话题详情">
					<template slot-scope="scope">
						<el-button @click="handleSeen(scope.row)">查看</el-button>
					</template>
				</el-table-column>
				<el-table-column label="跟帖">
					<template slot-scope="scope">
						<el-button @click="handleSeenComments(scope.row)">查看跟帖</el-button>
					</template>
				</el-table-column>
				<el-table-column prop="dtHtType" label="分类"></el-table-column>
				<el-table-column label="置顶">
					<template slot-scope="scope">
						<el-button @click="placeTop(scope.row)" v-if="scope.row.isTop==0">置顶</el-button>
						<el-button @click="placeTopCancel(scope.row)" v-if="scope.row.isTop==1" class="red">取消置顶</el-button>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="100">
					<template slot-scope="scope">
						<el-button @click="handleDelete(scope.row)" class="red">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="fenyeMargin">
				<el-button @click="toggleSelection(tableData)" class="allSelect">全选</el-button>
				<el-button @click="handleDeleteAll" class="allDelete">批量删除</el-button>
				<div class="pag_block">
					<el-pagination @current-change="handleCurrentChange" :current-page="currentpage" :page-size="pagesize" layout="prev, pager, next" :total="total"></el-pagination>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	import alert from '../../components/Alert.vue';
	import deleteAlert from '../../components/deleteAlert.vue';
	export default {
		data() {
			return {
				topicManager:'',
				search:'',
				sift:'',
				permission:'',
				permissionArr:[],
				tableData:[],
				multipleSelection: [],
		        pagesize: 15,
		        currentpage: 1,
		        total: 1,
		        deleteType:'delete'
			}
		},
		methods: {
			getTableList(){
				this.$ajax({
					url: this.$root.jifuUrl + "/getHtListPage?"+'page='+this.currentpage+'&num='+this.pagesize+'&sift='+this.sift+'&dtHtType='+this.permission+'&name='+this.search+'&rootcompanyid=1',
					method: 'GET',
					data: {},
					success: res => {
						if(res.data.code == 200) {
							this.tableData = res.data.data.list;
							this.total=res.data.data.pageParam.items;
						}else{
							this.failText = res.data.message;
							this.$rootFunction().deleteResFail();
						}
					}
				});
			},
			placeTop(row){
				let s = {htId:row.id};
				this.$ajax({
                    url: this.$root.jifuUrl + '/topHt',
                    method: 'POST',
                    data: this.qs.stringify(s),
                    success: res => {
                        if(res.data.code == 200) {
							this.$rootFunction().addResSuccess();
                        }else{
							this.failText = res.data.message;
							this.$rootFunction().deleteResFail();	
						}
                    }
                });
			},
			placeTopCancel(row){
				let s = {htId:row.id};
				this.$ajax({
                    url: this.$root.jifuUrl + '/noTopHt',
                    method: 'POST',
                    data: this.qs.stringify(s),
                    success: res => {
                        if(res.data.code == 200) {
							this.$rootFunction().addResSuccess();
                        }else{
							this.failText = res.data.message;
							this.$rootFunction().deleteResFail();
						}
                    }
                });
			},
			handleDelete(row){
				this.transitionRow = row;
				this.$rootFunction().rootDelete();
			},
			handleDeleteAll() {
				this.$rootFunction().rootDeleteAll();
			},
			deleteSubmit() {
				if(this.deleteType == 'delete'){
					let arr = [];
					arr.push(this.transitionRow.id);
					let s = arr;
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/qzDtHt/deleteQzDtList",
						headers:{'ContentType': 'application/json; charset=utf-8'},
						method: 'POST',
						data:s,
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}else{ 
					let s=this.multipleSelection;
					this.$ajax({ 
						url: this.$root.jifuUrl + "/mns/qzDtHt/deleteQzDtList",
						headers:{'ContentType': 'application/json; charset=utf-8'},
						method: 'POST',
						data:s,
						success: res => {
							if(res.data.code == 200) {
								this.$rootFunction().deleteResSuccess();
							}else{
								this.failText = res.data.message;
								this.$rootFunction().deleteResFail();
							}
						}
					});
				}
			},
			handleSeen(row){
				console.log(row);
				this.$router.push({
					name:'topicContent',
					params: {
						countId:row.id
					}
				})
			},
			handleSeenComments(row){
				this.$router.push({
					name:'topicCommentList',
					params: {
						countId:row.id,
						updateTitle:row.title,
						pathKey:'topicManager'
					}
				})
			},
			topicAudit(){
				this.$router.push({
					name:'topicAuditList'
				})
			},
			fenleiButton(){
				this.$router.push({
					name:'topicClassify'
				})
			},
			toggleSelection(rows) {
				if(rows) {
					rows.forEach(row => {
						this.$refs.multipleTable.toggleRowSelection(row, !this.allSelect)
					})
					this.allSelect = !this.allSelect;
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = [];
				val.forEach(row => {
					this.multipleSelection.push(row.id);
				})
			},
			handleCurrentChange(value) {
				this.currentpage = value;
				this.getTableList();
			},
			getPageSearch(){
				this.currentpage=1;
				this.getTableList();
			},
			importDaoChu(){
				
			},
			getTagType(){
				let tagType = 7;
				this.$rootFunction().tagType({tagType});
			},
		},
		components: {
			alert,
			deleteAlert
		},
		mounted: function() {
			this.getTableList();
			this.getTagType();
			this.topicManager = this.$root.huasan.topicManager;
		}
	}
</script>
<style>
	.topicManager .advise{border: 1px solid #44CEF6;box-sizing: border-box;margin-left: 20px;position: relative;top: 1px;}
</style>